package com.example.springtest.teacher.controller;

import com.example.springtest.common.R;
import com.example.springtest.teacher.pojo.Teacher;
import com.example.springtest.teacher.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("teacher")
@Slf4j
public class TeacherController {

   @Autowired
    private TeacherService teacherService;

    /**
     * 获取教师
     * @return
     */
    @GetMapping("list")
    public R<List<Teacher>> getTeacherList(){
    List<Teacher> teacherList=teacherService.getTeacherList();
    return R.ok(teacherList);

}

 /**
  * 增加教师
  * @param teacher
  * @return
  */
    @PostMapping("add")
    public R<Void> addTeacher(@RequestBody @Validated Teacher teacher){
     teacherService.addTeacher(teacher);
     return R.ok();
}

    /**
     * 删除教师
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
     public R<Void> deleteTeacher(@PathVariable Integer id){
        teacherService.deleteTeacher(id);
        return R.ok();
     }

    /**
     * 编辑教师
     * @param id
     * @param teacher
     * @return
     */
     @PutMapping("edit/{id}")
     public R<Void> editTeacher(@PathVariable Integer id,@RequestBody @Validated Teacher teacher){
        teacherService.editTeacher(id,teacher);
        return R.ok();
     }
}
